<template>
  <div>
    <div class="btn">
      <el-button type="primary" @click="showDilog" 
        >添加</el-button
      >
    </div>
    <lists :goodArr="goodArr" @updataCate="updataCate" @updataList="updataList"></lists>
    <forms
      :obj="obj"
      :catesArr="catesArr"
      @addCate="addCate"
      ref="curForm"
      @updataList="updataList"
      @canle="canle"
    ></forms>
  </div>
</template>

<script>
import { getMenuAll, cateList, getCates } from "../../request/api.js";
import lists from "./list.vue";
import forms from "./form.vue";
export default {
  components: {
    lists,
    forms,
  },
  data() {
    return {
      obj: {
        isshow: false,
      },
      catesArr: [], //上级分类列表
      goodArr: [],
    };
  },
  methods: {
    canle(){
      this.obj.isshow = false
    },
    updataList() {
      this.obj.isshow = false;
      this.getcateList();
    },
    updataCate(id) {
      this.obj.isshow = true;
      this.$refs.curForm.getCateInfo(id);
    },
    showDilog() {
      this.obj.isshow = true;
    },
    addCate() {
      this.obj.isshow = false;
      this.getcateList();
    },
    getcateList() {
      //商品列表
      cateList()
        .then((d) => {
          if (d.data.code == 200) {
            this.goodArr = d.data.list;
          }
        })
        .catch((e) => {
          console.log(e);
        });
    },
  },
  mounted() {
    getMenuAll()
      .then((d) => {
        // console.log(d);
      })
      .catch((e) => {
        console.log(e);
      });
    this.getcateList();
    //商品分类信息
    getCates()
      .then((d) => {
        if (d.data.code == 200) {
          this.catesArr = d.data.list;
        }
      })
      .catch((e) => {
        console.log(e);
      });
  },
};
</script>

<style>
.btn {
  margin: 30px 0;
}
</style>